package ua.org.nuos.sdms.clientgui.server;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
import ua.org.nuos.sdms.clientgui.client.ClientApplication;
import ua.org.nuos.sdms.middle.entity.enums.Role;

import javax.annotation.security.DeclareRoles;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 02.10.11
 * Time: 19:30
 * To change this template use File | Settings | File Templates.
 */
@DeclareRoles({Role.administrator, Role.client})
@WebServlet(urlPatterns = "/*")
public class ClientGuiServlet extends AbstractApplicationServlet {
    private static Logger logger = Logger.getLogger(ClientApplication.class.getName());

    @Inject
    Instance<ClientApplication> application;

    @Override
    protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
        return ClientApplication.class;
    }

    @Override
    protected Application getNewApplication(HttpServletRequest request) throws ServletException {
        try {
            return application.get();
        } catch (Exception ex) {
            logger.log(Level.SEVERE, "Application initialization error.", ex);
            throw new RuntimeException(ex);
        }
    }
}
